﻿onmessage = function(event) {
  var p = 0;
  var current_p;
  var num = event.data;
  var result = 0;

  for (var i = 0; i <= num; i++) {
    current_p = Math.floor(i * 100 / num);
    if (current_p > p) {
      p = current_p;
      // 現在の進捗を通知する
      postMessage({isDone: false, value: p});
    }

    result += i;
  }
  // 計算結果を返す
  postMessage({isDone: false, value: 100});
  postMessage({isDone: true, value: result});
};
